package com.guomao.controller;


import com.guomao.entity.Brand;
import com.guomao.feign.BrandClient;
import com.guomao.tools.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
//@RestController
public class BrandController {

    @Autowired
    private BrandClient brandClient;


    @RequestMapping("/brand_getBrands")
//    public Message getBrands(Model m) {
    public String getBrands(Model m) {
        List<Brand> list = brandClient.getBrands();
//        Message<Brand> message = new Message<Brand>();
//        message.setCode(200);
//        message.setMessage("查询成功");
//        message.setList(list);
        m.addAttribute("brands", list);
        return "brand";
    }

    @RequestMapping("/brand_delete")
    @ResponseBody
    public Message deleteBrandById(Integer id) {
//        boolean flag = brandClient.deleteBrand(id);
        Message message = new Message();
        if (brandClient.deleteBrand(id)) {
            message.setCode(200);
            message.setMessage("success");
        } else {
            message.setCode(500);
            message.setMessage("fail");
        }
        return message;
    }
}
